<?php
	$user = $controller->getCurrentUser();    
	//on verifie les permissions
	if ($user->isAllowedTo(GRADE_MOD_BOOK))
	{
		$albumId = $request->getParam('albumId');
		$editionId = $request->getParam('editionSelect');
		
		$book = new book();
		$edition = edition::singleton($editionId);
		$album = album::singleton($albumId);
		
		$book->setEditionObject($edition);
		$book->setAlbumObject($album);
		$book->setIdEdition($edition->getId());
		$book->getEditionObject()->setIdalbum($album->getId());
		
		if ($description = $request->getParam('bookDescription'))           $book->setDescription($description);
		if ($emplacement = $request->getParam('bookEmplacement'))           $book->setLocation($emplacement);
		if ($cotation = $request->getParam('bookCotation'))                 $book->setCotation($cotation);
		if ($condition = $request->getParam('bookCondition'))               $book->setCondition($condition);
		if ($drawerList = $request->getParam('drawerList'))                 $book->setDrawerList($drawerList);
		if ($scriptWritterList = $request->getParam('scriptWritterList'))   $book->setScriptWritterList($scriptWritterList);
		
		if ($book->isReadyToAdd() && $albumId  && $editionId && is_numeric($albumId) && is_numeric($editionId))
		{
			$book->add($albumId, $editionId);
			$logPermAction = 'BD ajout&eacute;e  : '.addslashes($book->getName());
			logPermactions($user->getId(), $logPermAction);
			$controller->addInformation('L\'album a bien &eacute;t&eacute; enregistr&eacute; !');
		}
		else
			$controller->addError('Veuillez remplir les champs necessaires !');    

		$request->clean('post');
		$controller->forward('addBook');
	}
	else
		$controller->render('errorRights');
  
?>
